import Dexie from "dexie";

const defaultVersion = 1;
// 创建smartformDB数据库
export const smartformDB = new Dexie("smartformDB");
smartformDB.version(defaultVersion).stores({
  // 定义存储对象，相当于表：cacheKey为userId&pageCode
  smartformCacheTable:
    "&cacheKey,cacheCreateTime,cssCode,designData,jsCode,watchProp"
});

export const queryOne = (db, tableName, searchKey, searchValue) => {
  return db[tableName]
    .where(searchKey)
    .equals(searchValue)
    .first();
};

export const del = (db, tableName, conditionKey, conditionValue) => {
  db[tableName]
    .where(conditionKey)
    .equals(conditionValue)
    .delete();
};

export const add = (db, tableName, data) => {
  db[tableName].add(data);
};
